package com.bosssoft.user.permission.center.serve.controller;

import com.bosssoft.user.permission.center.serve.api.LoginApi;
import com.bosssoft.user.permission.center.serve.pojo.query.LoginQuery;
import com.bosssoft.user.permission.center.serve.pojo.vo.LoginVO;
import com.bosssoft.user.permission.center.serve.pojo.vo.RouteVO;
import com.bosssoft.user.permission.center.serve.service.LoginService;
import common.data.commonresponse.CommonResponse;
import common.util.CommonResponseUtils;
import common.util.MyBeanUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;

/**
 * @className: com.bosssoft.user.permission.center.LoginController
 * @description: 当前版本针对前端的页面实现相应的功能接口,特别说明如下：
 * 1、接口注解做参数非空等检查
 * 2、控制层不处理异常，异常交给统一异常处理
 * 3、控制层的返回参数被统一包转为公共类型
 * @author: lanyukai
 * @date: 2024/6/11 13:44
 * @since 1.0
 **/
@RestController
@Validated
public class LoginController implements LoginApi {
    @Autowired
    private LoginService loginService;

    @Override
    public CommonResponse<LoginVO> login(@NotNull @Valid LoginQuery loginQuery) {
        return CommonResponseUtils.success(MyBeanUtil.copyProperties(loginService.login(loginQuery), LoginVO::new));
    }

    @Override
    public CommonResponse<RouteVO> createDynamicRoute() {
        return CommonResponseUtils.success(MyBeanUtil.copyProperties(loginService.createDynamicRoute(), RouteVO::new));
    }
}

